{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deployment for the eNB/gNB with dashboard\n",
    "\n",
    "Until this date, only the Monolithic mode works with the dashboard.\n",
    "\n",
    "**Step 1:** open a new terminal using ctrl+Alt+T and type:\n",
    "\n",
    "sudo su\n",
    "\n",
    "cd /home/dco1020/openairinterface5g/cmake_targets/ran_build/build/\n",
    "\n",
    "- For 5G\n",
    "\n",
    "sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf --gNBs.[0].min_rxtxtime 6 --continuous-tx -d \n",
    "\n",
    "- For 4G\n",
    "\n",
    "sudo -E ./lte-softmodem --rfsim -O ../../../ci-scripts/conf_files/enb2.band7.25prb.rfsim.conf --eNBs.[0].rrc_inactivity_threshold 0 2>&1 -d\n",
    "\n",
    "![gNB_config_07](../FIGS/H02_5GRAN_UNI_III/gNB_config_07.png)\n",
    "\n",
    "NRscope graphs ([Reference](https://openairinterface.org/wp-content/uploads/2022/06/OAI-Webinar-Series-Chapter-Four-Presentation-Slides.pdf))\n",
    "\n",
    "![nrscope](../FIGS/H02_5GRAN_UNI_III/nrscope.png)\n",
    "\n",
    "**Step 2**: To check the connection of gNodeB to the Core, see AMF logs. Open another terminal (the third one) using ctrl+Alt+T and type: \n",
    "\n",
    "docker logs -f oai-amf\n",
    "\n",
    "The expected return is shown in figure below, where gNodeB shows the connected status.\n",
    "\n",
    "![gNB_config_06](../FIGS/H02_5GRAN_UNI_III/gNB_config_06.png)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deployment for the UE with dashboard\n",
    "\n",
    "OAI-nrUE deployment with dashboard.\n",
    "\n",
    "**Step 1:** open a new terminal using ctrl+Alt+T and type:\n",
    "\n",
    "sudo su\n",
    "\n",
    "cd /home/dco1020/openairinterface5g/cmake_targets/ran_build/build/\n",
    "\n",
    "- For 5G\n",
    "\n",
    "sudo RFSIMULATOR=192.168.70.129 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf -d\n",
    "\n",
    "- For 4G\n",
    "\n",
    "sudo -E ./lte-uesoftmodem --rfsim -C 2680000000 -r 25 --ue-rxgain 140 --ue-txgain 120 --rfsimulator.serveraddr 192.168.61.20 --log_config.global_log_options level,nocolor,time -O ../../../ci-scripts/conf_files/lteue.usim-ci.conf -d\n",
    "\n",
    "![gNB_config_06](../FIGS/H03_5GUE_UNI_III/UE_config_07.png)\n",
    "\n",
    "UEscope graphs ([Reference](https://openairinterface.org/wp-content/uploads/2022/06/OAI-Webinar-Series-Chapter-Four-Presentation-Slides.pdf))\n",
    "\n",
    "![uescope](../FIGS/H03_5GUE_UNI_III/uescope.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Channel Simulation with dashboard\n",
    "\n",
    "Tutorial made based on the [link](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md).\n",
    "\n",
    "**Step 1:** Create the channel simulation file. \n",
    "\n",
    "cd /home/dco1020/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/\n",
    "\n",
    "touch channelmod_rfsimu.conf\n",
    "\n",
    "**Step 2:** Open the channelmod_rfsimu.conf and add the following lines: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "```\n",
    "channelmod = {\n",
    "  max_chan = 10;\n",
    "  modellist = \"modellist_rfsimu_1\";\n",
    "  modellist_rfsimu_1 = (\n",
    "    {\n",
    "      model_name     = \"rfsimu_channel_enB0\"\n",
    "      type           = \"AWGN\";\n",
    "      ploss_dB       = 20;\n",
    "      noise_power_dB = -4;\n",
    "      forgetfact     = 0;\n",
    "      offset         = 0;\n",
    "      ds_tdl         = 0;\n",
    "    },\n",
    "    {\n",
    "      model_name     = \"rfsimu_channel_ue0\"\n",
    "      type           = \"AWGN\";\n",
    "      ploss_dB       = 20;\n",
    "      noise_power_dB = -2;\n",
    "      forgetfact     = 0;\n",
    "      offset         = 0;\n",
    "      ds_tdl         = 0;\n",
    "    }\n",
    "  );\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "These lines are the configuration parameters for the gNB and UE channels.\n",
    "\n",
    "**Step 3:** Open the /home/dco1020/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf\n",
    "\n",
    "cd /home/dco1020/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf\n",
    "\n",
    "**Step 4:** Add the line below in the end of gnb.sa.band78.fr1.106PRB.usrpb210.conf.\n",
    "\n",
    "@include \"channelmod_rfsimu.conf\"\n",
    "\n",
    "**Step 5:** Open the file /home/dco1020/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf \n",
    "\n",
    "cd /home/dco1020/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf\n",
    "\n",
    "\n",
    "**Step 6:** Add the following lines in the end of ue.conf."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "```\n",
    "channelmod = {\n",
    "  max_chan = 10;\n",
    "  modellist = \"modellist_rfsimu_1\";\n",
    "  modellist_rfsimu_1 = (\n",
    "    {\n",
    "      model_name     = \"rfsimu_channel_enB0\"\n",
    "      type           = \"AWGN\";\n",
    "      ploss_dB       = 20;\n",
    "      noise_power_dB = -4;\n",
    "      forgetfact     = 0;\n",
    "      offset         = 0;\n",
    "      ds_tdl         = 0;\n",
    "    },\n",
    "    {\n",
    "      model_name     = \"rfsimu_channel_ue0\"\n",
    "      type           = \"AWGN\";\n",
    "      ploss_dB       = 20;\n",
    "      noise_power_dB = -2;\n",
    "      forgetfact     = 0;\n",
    "      offset         = 0;\n",
    "      ds_tdl         = 0;\n",
    "    }\n",
    "  );\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "**Step 7:** Deploy OAI gNB:\n",
    "\n",
    "sudo ./nr-softmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf --gNBs.[0].min_rxtxtime 6 --rfsim --sa --rfsimulator.options chanmod --telnetsrv --channelmod.modellist modellist_rfsimu_1 -d\n",
    "\n",
    "**Step 8:** Deploy OAI UE:\n",
    "\n",
    "sudo RFSIMULATOR=192.168.70.129 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf --rfsimulator.options chanmod --telnetsrv --telnetsrv.listenport 9091 -d\n",
    "\n",
    "**Step 8:** Deploy gNB telnet server:\n",
    "\n",
    "telnet 127.0.0.1 9090\n",
    "\n",
    "**Step 8:** Deploy OAI-UE telnet server:\n",
    "\n",
    "telnet 127.0.0.1 9091\n",
    "\n",
    "**Step 10:** Variate the parameters below using channelmod modify.\n",
    "\n",
    "| Parameter | Range | Description |\n",
    "|---|---|---|\n",
    "| riceanf | 0 to 1 | Ricean factor, of first tap w.r.t. other taps (where 0 means AWGN and 1 means Rayleigh channel) |\n",
    "| aoa | 0 to 2π | Angle of arrival of wavefront (in radians). For Ricean channel only. This assumes that both RX and TX have linear antenna arrays with lambda/2 antenna spacing. Also it is assumed that the arrays are parallel to each other and that they are far enough apart so that we can safely assume plane wave propagation. |\n",
    "| randaoa | 0 to 1 | randomized angle of arrival according to a uniform random distribution |\n",
    "| ploss | - | total path loss of the channel including shadow fading, in dB |\n",
    "| noise_power_dB | - | Noise power in dB, used to compute the SNR. Its value is proportional to the noise added. |\n",
    "| forgetf | 0 to 1  | Forgetting factor, allows for simple 1st order temporal variation. 0 means a new channel every call, 1 means keep channel constant all the time |\n",
    "\n",
    "Reference: [link](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md)\n",
    "\n",
    "Example of channelmod: \n",
    "\n",
    "channelmod modify \\<index of gNB or UE\\> \\<parameter\\> \\<value\\> \n",
    "\n",
    "**Important:** The gNB index is 1, and the UE index is 0. You need to put the command in the respective telnet terminal.  \n",
    "\n",
    "software_gnb> channelmod modify 0 ploss 12\n",
    "\n",
    "software_5gue> channelmod modify 1 noise_power_dB 12\n",
    "\n",
    "**OBS:** This example was created using the AWGN channel model, but you can test it with various channel models. You can explore all available channel models  in /home/dco1020/openairinterface5g/openair1/SIMULATION/TOOLS/sim.h."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
